package cn.jia.websocket.config;

import cn.jia.websocket.MarcoHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/4/23 11:49
 * @Modified By:
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    /**
     * @Author: jia
     * @Date: 2018/4/23 11:50
     * @Modified By: jia
     * @Descirption: 注册websocket处理器
     */
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(marcoHandler(),"/marco").withSockJS();
    }

    @Bean
    public MarcoHandler marcoHandler(){
        return new MarcoHandler();
    }


}
